//
//  HotBrainStormFromTableViewCell.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/13.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "HotBrainStormFromTableViewCell.h"

@implementation HotBrainStormFromTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self.contentView addSubview:self.iconTouxiang]; // 头像
        [self.contentView addSubview:self.nameText]; // 名称
        [self.contentView addSubview:self.guanzhuBut]; // 关注
        [self.contentView addSubview:self.iconXunzhang]; // 等级勋章
        [self.contentView addSubview:self.textDengji]; // 等级
        [self.contentView addSubview:self.iconGuankan]; // 浏览人数图片
        [self.contentView addSubview:self.numLable];  // 浏览人数
        [self.contentView addSubview:self.contentText]; // 标题
        [self.contentView addSubview:self.labellingBtn]; // 行业标签
        [self.contentView addSubview:self.iconShijian];  //  时间图标
        [self.contentView addSubview:self.shiJianText];  //  发布时间
        [self.shadowView addSubview:self.shangYeText];
        [self.contentView addSubview:self.shadowView]; //  内容简介
        [self.contentView addSubview:self.zuijiaText];  //  最佳评论标签
        
        [self showNaoBaoCell];
    }
    return self;
}

// 重写表格位置，使每一行cell都分隔开
- (void)setFrame:(CGRect)frame{
    //    frame.origin.x += 10;
    frame.origin.y += 10;
    frame.size.height -= 10;
    //    frame.size.width -= 20;
    [super setFrame:frame];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}

- (void)showNaoBaoCell
{
    _iconTouxiang.sd_layout
    .topSpaceToView(self.contentView, kHeightScale(20))
    .leftSpaceToView(self.contentView, kWidthScale(13))
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(35));
    
    _nameText.sd_layout
    .topSpaceToView(self.contentView,kHeightScale(13))
    .leftSpaceToView(self.iconTouxiang,kWidthScale(10))
    .widthIs(kWidthScale(150))
    .heightIs(kHeightScale(20));
    
    _guanzhuBut.sd_layout
    .topSpaceToView(self.contentView,kHeightScale(20))
    .rightSpaceToView(self.contentView,kWidthScale(10))
    .widthIs(kWidthScale(60))
    .heightIs(kHeightScale(25));
    
    _iconXunzhang.sd_layout
    .topSpaceToView(self.nameText,kHeightScale(5))
    .leftEqualToView(self.nameText)
    .widthIs(kWidthScale(10))
    .heightIs(kHeightScale(10));
    
    _textDengji.sd_layout
    .topEqualToView(self.iconXunzhang)
    .leftSpaceToView(self.iconXunzhang,kWidthScale(10))
    .widthIs(kWidthScale(20))
    .heightIs(kHeightScale(10));
    
    _iconGuankan.sd_layout
    .topEqualToView(self.textDengji)
    .leftSpaceToView(self.textDengji,kWidthScale(10))
    .widthIs(kWidthScale(12))
    .heightIs(10);
    
    _numLable.sd_layout
    .topEqualToView(self.iconGuankan)
    .leftSpaceToView(self.iconGuankan,kWidthScale(10))
    .widthIs(kWidthScale(20))
    .heightIs(kHeightScale(10));
    
    _contentText.sd_layout
    .topSpaceToView(self.iconTouxiang,kHeightScale(10))
    .leftEqualToView(self.iconTouxiang)
    .rightEqualToView(self.guanzhuBut)
    .heightIs(kHeightScale(20));
    
    _labellingBtn.sd_layout
    .topSpaceToView(self.contentText,kHeightScale(5))
    .leftEqualToView(self.contentText)
    .widthIs(kWidthScale(35))
    .heightIs(kHeightScale(20));
    
    _iconShijian.sd_layout
    .topEqualToView(self.labellingBtn)
    .leftSpaceToView(self.labellingBtn,kWidthScale(5))
    .widthIs(kWidthScale(21))
    .heightIs(kHeightScale(21));
    
    _shiJianText.sd_layout
    .topEqualToView(self.iconShijian)
    .leftSpaceToView(self.iconShijian,kWidthScale(5))
    .widthIs(kWidthScale(50))
    .heightIs(21);
    
    _shadowView.sd_layout
    .topSpaceToView(self.labellingBtn,kHeightScale(6))
    .leftEqualToView(self.labellingBtn)
    .rightEqualToView(self.guanzhuBut)
    .heightIs(kHeightScale(55));
    
    _shangYeText.sd_layout
    .topEqualToView(self.shadowView)
    .leftEqualToView(self.shadowView)
    .rightEqualToView(self.shadowView)
    .heightIs(kHeightScale(55));
    
    _zuijiaText.sd_layout
    .topSpaceToView(self.shadowView,kHeightScale(22))
    .leftEqualToView(self.shadowView)
    .widthIs(kWidthScale(64))
    .heightIs(kHeightScale(20));
    
    for (int i = 0; i < 5; i++) {
        _bestHeadImage = [[UIImageView alloc] initWithFrame:CGRectMake(kWidthScale(84) * (i+1) - (66*i), kHeightScale(188), kWidthScale(23), kHeightScale(23))];
        _bestHeadImage.image = [UIImage imageNamed:@"toixiang"];
        [self.contentView addSubview:self.bestHeadImage]; //  最佳评论用户头像
    }
    [self.contentView addSubview:self.addTX];   // ➕
    _addTX.sd_layout
    .topEqualToView(self.bestHeadImage)
    .leftSpaceToView(self.bestHeadImage,kWidthScale(-5))
    .widthIs(kWidthScale(23))
    .heightIs(kHeightScale(23));
}
// 头像
- (UIButton *)iconTouxiang
{
    if (!_iconTouxiang)
    {
        _iconTouxiang = [UIButton buttonWithType:UIButtonTypeCustom];
        [_iconTouxiang setImage:[UIImage imageNamed:@"toixiang"] forState:0];
    }
    return _iconTouxiang;
}
// 名字
- (UILabel *)nameText
{
    if (!_nameText)
    {
        _nameText = [[UILabel alloc] init];
        _nameText.text=@"后悔的小公主";
        _nameText.font=[UIFont systemFontOfSize:kWidthScale(15)];
        _nameText.textColor=[UIColor colorWithRed:(0/255) green:(0/255) blue:(0/255) alpha:1];
    }
    return _nameText;
}
// 关注
- (UIButton *)guanzhuBut
{
    if (!_guanzhuBut)
    {
        _guanzhuBut = [UIButton buttonWithType:UIButtonTypeCustom];
        [_guanzhuBut setBackgroundImage:[UIImage imageNamed:@"guanzhu"] forState:0];
    }
    return _guanzhuBut;
}
// 等级勋章
- (UIImageView *)iconXunzhang
{
    if (!_iconXunzhang)
    {
        _iconXunzhang = [[UIImageView alloc] init];
        _iconXunzhang.image=[UIImage imageNamed:@"dengji"];
    }
    return _iconXunzhang;
}
// 等级
- (UILabel *)textDengji
{
    if (!_textDengji)
    {
        _textDengji = [[UILabel alloc] init];
        _textDengji.text=@"1级";
        _textDengji.textColor=[UIColor colorWithRed:(0/255) green:(0/255) blue:(0/255) alpha:1];
        _textDengji.font=[UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _textDengji;
}
// 观看人数图片
- (UIImageView *)iconGuankan
{
    if (!_iconGuankan)
    {
        _iconGuankan = [[UIImageView alloc] init];
        _iconGuankan.image=[UIImage imageNamed:@"liulan"];
    }
    return _iconGuankan;
}
// 观看人数
- (UILabel *)numLable
{
    if (!_numLable)
    {
        _numLable = [[UILabel alloc] init];
        _numLable.text=@"13";
        _numLable.textColor=[UIColor colorWithRed:(0/255) green:(0/255) blue:(0/255) alpha:1];
        _numLable.font=[UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _numLable;
}
// 标题
- (UILabel *)contentText
{
    if (!_contentText)
    {
        _contentText = [[UILabel alloc] init];
        _contentText.textColor=[UIColor colorWithRed:(0/255) green:(0/255) blue:(0/255) alpha:1];
        _contentText.text=@"什么时候觉得，数据分析真的非常有用";
        _contentText.font = [UIFont systemFontOfSize:kWidthScale(13)];
    }
    return _contentText;
}
// 行业标签
- (UIButton *)labellingBtn
{
    if (!_labellingBtn)
    {
        _labellingBtn = [[UIButton alloc] init];
        [_labellingBtn setBackgroundImage:[UIImage imageNamed:@"shangye"] forState:0];
    }
    return _labellingBtn;
}
// 时间图标
- (UIImageView *)iconShijian
{
    if (!_iconShijian)
    {
        _iconShijian = [[UIImageView alloc] init];
        _iconShijian.image=[UIImage imageNamed:@"time"];
    }
    return _iconShijian;
}
// 具体发布时间
- (UILabel *)shiJianText
{
    if (!_shiJianText)
    {
        _shiJianText = [[UILabel alloc] init];
        _shiJianText.text=@"8.15";
        _shiJianText.textColor=[UIColor colorWithRed:(0/255) green:(0/255) blue:(0/255) alpha:1];
        _shiJianText.font=[UIFont systemFontOfSize:kWidthScale(13)];
    }
    return _shiJianText;
}
// 内容简介
- (KQlable *)shangYeText
{
    if (!_shangYeText)
    {
        _shangYeText = [[KQlable alloc] init];
        _shangYeText.text=@"风暴简介：个环境可凉快和包教包零零落落零零落落零零落落零零落落零零落落啦啦啦";
        _shangYeText.backgroundColor = [UIColor colorWithHexString:@"#666666"];
        _shangYeText.textColor=[UIColor blackColor];
        _shangYeText.font=[UIFont systemFontOfSize:kWidthScale(13)];
        _shangYeText.layer.cornerRadius = kWidthScale(12);
        _shangYeText.layer.masksToBounds = YES;
    }
    return _shangYeText;
}
- (void)drawTextInRect:(CGRect)rect {
    UIEdgeInsets insets = {0, 5, 0, 5};
    [self drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}

// 最佳评论
- (UILabel *)zuijiaText
{
    if (!_zuijiaText)
    {
        _zuijiaText = [[UILabel alloc] init];
        _zuijiaText.textColor=[UIColor colorWithRed:(0/255) green:(0/255) blue:(0/255) alpha:1];
        _zuijiaText.font=[UIFont systemFontOfSize:kWidthScale(13)];
        _zuijiaText.text = @"最佳评论";
    }
    return _zuijiaText;
}

// ➕
- (UIButton *)addTX
{
    if (!_addTX)
    {
        _addTX = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addTX setBackgroundImage:[UIImage imageNamed:@"tianjia"] forState:UIControlStateNormal];
    }
    return _addTX;
}

- (UIView *)shadowView
{
    if (!_shadowView)
    {
        _shadowView = [[UIView alloc] init];
        _shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
        _shadowView.layer.shadowOffset = CGSizeMake(0, 5);
        _shadowView.layer.shadowOpacity = 0.5;
        _shadowView.layer.shadowRadius = 6.0;
        _shadowView.layer.cornerRadius = 6.0;
        _shadowView.clipsToBounds = NO;
    }
    return _shadowView;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
